package com.tjcd.project.library_base.common.utils;

import android.content.Context;

import com.hjq.permissions.OnPermissionCallback;
import com.hjq.permissions.XXPermissions;

import java.util.List;

/**
 * @Author jiangKunKun
 * @CreateDate 2021/7/13
 * @Description 权限申请
 * @SpittingGrooves
 */
public class PermissionsUtil {
    public interface PermissionListener {
        void onSuc(List<String> permissions, boolean all);
        void onFail(List<String> permissions, boolean never);
    }

    /**
     * @param context
     * @param listener 监听
     * @param PermissionsGroup 权限数组
     */
    public static void setPermissions(Context context, PermissionListener listener, String... PermissionsGroup) {
        XXPermissions.with(context)
                .permission(PermissionsGroup)
                .request(new OnPermissionCallback() {
                    @Override
                    public void onGranted(List<String> permissions, boolean all) {
                        listener.onSuc(permissions, all);
                    }

                    @Override
                    public void onDenied(List<String> permissions, boolean never) {
                        listener.onFail(permissions, never);
                    }
                });
    }
}
